package com.kadron.embed;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.kadron.common.KConst;
import com.kadron.dao.KEmbedDAO;
import com.kadron.entity.Embed;
import com.kadron.manager.KMessageManager;

@AutoCreate
@Name("kEmbedManager")
@Scope(ScopeType.PAGE)
public class KEmbedManager extends KMessageManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4184026689307942094L;

	private static final Log log = LogFactory.getLog(KEmbedManager.class);
	
	private Embed embed; 
	
	@In
	private KEmbedDAO embedDAO;
	
	@Create
	public void init() {
		Long embedId = (Long) Component.getInstance("embedId");
		if (embedId == null) {
			embedId = new Long(0);
		}
		if (embedId > 0) {
			embed = (Embed) embedDAO.find(embedId, Embed.class);
		} else {
			embed = new Embed();
		}
	}
	
	public String save() {
		if (embed == null) {
			bad(KConst.BAD_THING);
			return null;
		}
		if (log.isDebugEnabled()) {
			log.debug("Save Embed embedId="+embed.getId());
		}
		embedDAO.update(embed);
		good();
		return "embed";
	}

	public Embed getEmbed() {
		return embed;
	}

	public void setEmbed(Embed embed) {
		this.embed = embed;
	}
}
